def isPrime(a):
    if a == 1: return False
    t = True
    s = a - 1
    while s > 1:
        if not a % s:
            t = False
            break
        s -= 1
    return t
f = input()
d = []
for i in range(4):
    for s in range(i + 1, 4 + 1):
        a = int(f[i:s])
        if isPrime(a):
            d += [a]
print(max(d) if d else 0)